<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        {include file="public/link"}
    </head>
    
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>品牌名</label>
                        <div class="layui-input-inline">
                            <input type="text" id="title" name="title" required="" lay-verify="title" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red"></span>封面图</label>
                        <div class="layui-input-inline">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="tem_img_up">上传封面图</button>
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" style="width: 100%" id="tem_img">
                                    <p id="demoText"></p>
                                    <input type="hidden" name="img" value="" style="width: 500px" id="tem_input_img">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red"></span>轮播图</label>
                        <div class="layui-input-inline">
                            <button type="button" class="layui-btn" id="CarouselImg">上传轮播图</button>
                            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                预览图：
                                <div class="layui-upload-list" id="Carousel" style="width: 100%;">
                                    <input type="hidden" id="image" name="image" value="">
                                </div>
                            </blockquote>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="cate" class="layui-form-label">
                            <span class="x-red">*</span>选择行业</label>
                        <div class="layui-input-inline" style="width: 89px">
                            <select name="cate_pid" id="cate_pid" lay-filter="cate_pid" >
                                {foreach $cate as $key => $value}
                                <option value="{$value.id}">{$value.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="url" class="layui-form-label">
                            <span class="x-red">*</span>品牌官网</label>
                        <div class="layui-input-inline">
                            <input type="text" id="url" name="url" required=""  autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="ame" class="layui-form-label">
                            <span class="x-red">*</span>品牌特色</label>
                        <div class="layui-input-inline">
                            <input type="text" id="ame" name="ame" required="" lay-verify="ame" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="phone" class="layui-form-label">
                            <span class="x-red"></span>联系方式</label>
                        <div class="layui-input-inline">
                            <input type="text" id="phone" name="phone" required="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="scope" class="layui-form-label">
                            <span class="x-red">*</span>经营范围</label>
                        <div class="layui-input-inline">
                            <input type="text" id="scope" name="scope" required="" lay-verify="scope" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    公司信息
                    <div class="layui-form-item">
                        <label for="company" class="layui-form-label">
                            <span class="x-red">*</span>公司名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="company" name="cname" required="" lay-verify="company" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red"></span>公司logo</label>
                        <div class="layui-input-inline">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="logo_up">上传封面图</button>
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" style="width: 100%" id="logo_img">
                                    <p id="logo"></p>
                                    <input type="hidden" name="logo" value="" style="width: 500px" id="input_logo">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="ceo" class="layui-form-label">
                            <span class="x-red">*</span>CEO</label>
                        <div class="layui-input-inline">
                            <input type="text" id="ceo" name="ceo" required="" lay-verify="company" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="ceo" class="layui-form-label">
                            <span class="x-red">*</span>注册资金</label>
                        <div class="layui-input-inline">
                            <input type="text" id="money" name="money" required="" lay-verify="company" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="address" class="layui-form-label">
                            <span class="x-red">*</span>注册地址</label>
                        <div class="layui-input-inline">
                            <input type="text" id="address" name="address" required="" lay-verify="address" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="shop_num" class="layui-form-label">
                            <span class="x-red">*</span>门店数量</label>
                        <div class="layui-input-inline">
                            <input type="text" id="shop_num" name="shop_num" required="" lay-verify="shop_num" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="city" class="layui-form-label">
                            <span class="x-red">*</span>加盟区域</label>
                        <div class="layui-input-inline" style="width: 89px">
                            <select name="province" id="province" lay-filter="province">
                                {foreach $city as $key => $value}
                                <option value="{$value.id}">{$value.cityname}</option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width: 89px;" >
                            <select name="city" id="city">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="shop_num" class="layui-form-label">
                            <span class="x-red">*</span>投资金额</label>
                        <div class="layui-input-inline" style="width: 85px;">
                            <input type="text" id="min_money" name="min_money" required="" lay-verify="money" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width: 85px;">
                            <input type="text" id="max_money" name="max_money" required="" lay-verify="money" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label for="sign" class="layui-form-label">描述</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" id="sign" name="sign" style="width: 800px;" class="layui-textarea"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label for="detail" class="layui-form-label">项目详情</label>
                        <div class="layui-input-block">
                        <script id="editor" name="detail" type="text/plain" style="width:800px;height:500px;"></script>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">增加</button>
                    </div>
        </form>
        </div>
        </div>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
        <script type="text/javascript" charset="utf-8" src="/Urditor/ueditor.config.js"></script>
        <script type="text/javascript" charset="utf-8" src="/Urditor/ueditor.all.min.js"> </script>
        <script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
        <script>
            var ue = UE.getEditor('editor');
            layui.use('upload', function(){
                var $ = layui.jquery
                    ,upload = layui.upload;

                //普通图片上传
                var uploadInst = upload.render({
                    elem: '#tem_img_up'
                    ,url: "{:url('admin/common/uploadImage')}"
                    ,before: function(obj){
                        //预读本地文件示例，不支持ie8
                        obj.preview(function(index, file, result){
                            $('#tem_img').attr('src', result); //图片链接（base64）
                        });
                    }
                    ,done: function(res){
                        //如果上传失败
                        if(res.code > 0){
                            return layer.msg('上传失败');
                        }
                        //上传成功
                        $('#tem_input_img').attr('value',res.data.src); //图片链接（base64）
                    }
                    ,error: function(){
                        //演示失败状态，并实现重传
                        var demoText = $('#demoText');
                        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                        demoText.find('.demo-reload').on('click', function(){
                            uploadInst.upload();
                        });
                    }
                });
                //公司logo上传
                var uploadInst = upload.render({
                    elem: '#logo_up'
                    ,url: "{:url('admin/common/uploadImage')}"
                    ,before: function(obj){
                        //预读本地文件示例，不支持ie8
                        obj.preview(function(index, file, result){
                            $('#logo_img').attr('src', result); //图片链接（base64）
                        });
                    }
                    ,done: function(res){
                        //如果上传失败
                        if(res.code > 0){
                            return layer.msg('上传失败');
                        }
                        //上传成功
                        $('#input_logo').attr('value',res.data.src); //图片链接（base64）
                    }
                    ,error: function(){
                        //演示失败状态，并实现重传
                        var demoText = $('#logo');
                        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                        demoText.find('.logo-reload').on('click', function(){
                            uploadInst.upload();
                        });
                    }
                });
                //多图片上传
                upload.render({
                    elem: '#CarouselImg'
                    ,url: "{:url('admin/common/uploadImage')}"
                    ,multiple: true
                    ,before: function(obj){
                        //预读本地文件示例，不支持ie8
                        obj.preview(function(index, file, result){
                            $('#Carousel').append('<img src="'+ result +'" style="width: 50px;" alt="'+ file.name +'" class="layui-upload-img">')
                        });
                    }
                    ,done: function(res){
                        //上传完毕
                        $('#image').val($("#image").val()+res.data.src+",");

                    }
                });
            });

            layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //监听提交
                form.on('submit(add)',
                function(data) {

                    console.log(data.field);
                    var field = data.field;
                    // field.detail = UE.getEditor('editor').getContent();
                    // console.log('data',field);
                    //发异步，把数据提交给php
                    $.ajax({
                        type: "POST",
                        url: "{:url('admin/brand/add_brand')}",
                        data:{
                            field:field,
                        },
                        success: function(returnData){
                            console.log('returnData',returnData);
                            if(returnData.code == 200){
                                layer.alert("增加成功", {
                                        icon: 6
                                    },
                                    function() {
                                        // 获得frame索引
                                        var index = parent.layer.getFrameIndex(window.name);
                                        //关闭当前frame
                                        parent.layer.close(index);
                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            }else{
                                layer.alert("内部错误", {
                                        icon: 5
                                    },
                                    function() {
                                        // 获得frame索引
                                        var index = parent.layer.getFrameIndex(window.name);
                                        //关闭当前frame
                                        parent.layer.close(index);
                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            }
                        }
                    });

                    return false;
                });
                //动态加盟区域 province
                form.on('select(province)', function(data){
                    var pid=data.value;
                    // console.log('pid',pid);
                    $.ajax({
                        type: "POST",
                        url: "{:url('admin/city/getCityDataList')}",
                        data:{
                            pid:pid,
                        },
                        success: function(returnData){
                            // console.log('returnData',returnData);
                            if(returnData.code == 200){
                                $("#city").html(false);
                                layui.each(returnData.data,function (index,item) {
                                    // console.log('item.id',item.id);
                                    // console.log('item.name',item.cityname);
                                    $("#city").append("<option value='"+item.cityname+"'>"+item.cityname+"</option>");
                                });
                                layui.form.render('select');//渲染
                            }else{
                                layer.alert('内部错误');
                            }
                        }
                    });
                });
            });
            layui.use(['laydate', 'form'],
                function() {
                    var laydate = layui.laydate;

                    //执行一个laydate实例
                    laydate.render({
                        elem: '#brand_make_time' //指定元素
                    });
                });
        </script>

    </body>

</html>